package com.mdz.sbgl.Controller;


import cn.hutool.http.HttpUtil;
import com.mdz.sbgl.Entity.Sbxxb;
import com.mdz.sbgl.Entity.Xsck;
import com.mdz.sbgl.Mapper.XsckMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.net.InetAddress;
import java.net.MalformedURLException;
import java.net.Socket;
import java.net.URL;
import java.util.ArrayList;
import java.util.List;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author 孟德志
 * @since 2020-12-18
 */
@Controller
@RequestMapping("/sbgl/xsck")
public class XsckController {

    @Autowired
    private XsckMapper xsckMapper;
    @ResponseBody
    @RequestMapping(value = "/insertxsck", method = RequestMethod.POST)
    public int insertxsck(Xsck xsck) {
        Integer flag=0;
        String[] sjshoum = xsck.getCode().split(",");
            for (int i = 0; i < sjshoum.length; i++) {
                System.out.println(sjshoum[i]);
                xsck.setCode(sjshoum[i]);
                flag+=xsckMapper.insert(xsck);
            }
            return flag;
    }

    public static void main(String[] args) {
        try {
            URL url=new URL("http://checkip.amazonaws.com");
            BufferedReader reader=new BufferedReader(new InputStreamReader(url.openStream()));
            String ipAddress=reader.readLine();
            System.out.println(ipAddress);
            reader.close();
            System.out.println(InetAddress.getLocalHost().getHostAddress());
            System.out.println(InetAddress.getByName("www.sina.com.cn"));
            Socket client=new Socket("192.168.10.107",9999);
            System.out.println(client.getInetAddress().getHostAddress());
        } catch (Exception e) {
            e.printStackTrace();
        }


//        try {
//            InetAddress inetAddress = InetAddress.getByName("www.google.com");
//            String externalIP = inetAddress.getHostAddress();
//            System.out.println("External IP: " + externalIP);
//        } catch (Exception e) {
//            e.printStackTrace();
//        }

        String ipV4="";
        String ipStr= HttpUtil.get("https://www.taobao.com/help/getip.php");//
        ipV4=ipStr.split(":")[1];
        System.out.println(ipStr);
        System.out.println(ipV4);
    }

}

